package cn.edu.nit.sys.controller;

import cn.edu.nit.sys.entity.Forum;
import cn.edu.nit.sys.entity.ForumLog;
import cn.edu.nit.sys.service.ForumService;
import cn.edu.nit.sys.utils.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Author 罗文斌
 * @Date 2023/4/11
 * @Version 1.0.0
 */
@RestController
@RequestMapping("/forum")
public class ForumController {

    @Autowired
    private ForumService forumService;

    @PostMapping
    public R addForum(@RequestBody Forum forum) {
        return forumService.addForum(forum);
    }

    @GetMapping
    public R getApproveList(Page<Forum> page, String siftName, String siftStatus, String startTime, String endTime, String uid) {
        return forumService.getApproveList(page, siftName, siftStatus, startTime, endTime, uid);
    }

    @PostMapping("/approve")
    public R approveForum(@RequestBody ForumLog forumLog) {
        return forumService.approveForum(forumLog);
    }

    @GetMapping("/detail")
    public R getDetail(@RequestParam("id")String id, @RequestParam("uid") String uid) {
        return forumService.getDetail(id, uid);
    }

    @GetMapping("/comment")
    public R getForumComment(Page<Map<String, String>> page, String id) {
        return forumService.getForumComment(page, id);
    }

    @PostMapping("/comment")
    public R addForumComment(@RequestBody Map<String, String> params) {
        return forumService.addForumComment(params);
    }

    @DeleteMapping("/comment/{id}")
    public R delComment(@PathVariable("id") String id) {
        return forumService.delComment(id);
    }

    @PutMapping("/views")
    public void plusView(@RequestBody Map<String, String> params) {
        String id = params.get("id");
        String uid = params.get("uid");
        forumService.plusView(id, uid);
    }

    @PutMapping("/likes")
    public R forumLikes(@RequestBody Map<String, String> params) {
        String fid = params.get("fid");
        String uid = params.get("uid");
        return forumService.forumLikes(fid, uid);
    }
}
